/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Desarrollo.Soft.Hibernate.Control.Consultas;

import Desarrollo.Soft.Hibernate.Data.Entity.Catproductos;
import Desarrollo.Soft.Hibernate.Data.Entity.Tblalmacen;
import Desarrollo.Soft.Hibernate.Util.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author ASPIRE
 */
public class ctrlAlmacen {

    private static Session sessionHibernate;

    public static <T> List<T> selectItemsbyIdProvedor(int id) {
        try {
            sessionHibernate = HibernateUtil.getSessionFactory().getCurrentSession();
            sessionHibernate.beginTransaction();
            Criteria crit = sessionHibernate.createCriteria(Catproductos.class, "catproductos")
                    .createAlias("catproductos.tblproductosproveedoreses", "tpP")
                    .createAlias("tpP.tblproveedores", "tp");
            crit.add(Restrictions.eq("tp.id", id));
            return crit.list();
        } catch (Exception e) {
            throw e;
        } finally {
            System.gc();
        }
    }
    
    public static <T> List<T> selectItemsbyId(int id) {
        try {
            sessionHibernate = HibernateUtil.getSessionFactory().getCurrentSession();
            sessionHibernate.beginTransaction();
            Criteria crit = sessionHibernate.createCriteria(Tblalmacen.class, "tblalmacen");
            crit.add(Restrictions.eq("tblalmacen.id", id));
            return crit.list();
        } catch (Exception e) {
            throw e;
        } finally {
            System.gc();
        }
    }
}
